/**
 * Created by albert on 2017/11/4.
 */
/**
 * Created by albert on 2017/11/2.
 */
import Api from "../../api/api"
import * as types from "../mutation-types"
import  {setParams} from "../../util/methods"
const state = {
    param: {
        "start_at": "",
        "end_at": "",
    },
    orderAll: 0,
    revokeOrder:0,
    cancelOrder:0,
    successOrder:0,
    refuseOrder:0,
    auditOrder:0
}
const actions = {
    orderStastic({commit}, payload){
        return new Promise((resolve, reject) => {
            Api.orderStastic(state.param)
                .then(res => {
                    commit({
                        type: "ORDER_STASTIC",
                        res,
                    })
                    resolve(res)
                }, err => {
                    reject(err)
                })
                .catch(err => {
                    reject(err)
                })
        })
    }
}
const mutations = {
    setDate(state, payload){
        state.param[payload.key]=payload.value
    },
    resetParam(state){
        state.param = {
            "start_at": "",
            "end_at": "",
        };
    },
    [types.ORDER_STASTIC](state, payload){
        state.successOrder= payload.res.success;
        state.cancelOrder= payload.res.cancel_order;
        state.revokeOrder= payload.res.revoke_order;
        state.auditOrder= payload.res.audit_order;
        state.refuseOrder= payload.res.refuse_order;
        state.orderAll= payload.res.sum_amount
    },
}
export default {
    state,
    actions,
    mutations,
}